//
//  JMCommonView.m
//  NewiOSProject
//
//  Created by li on 2023/9/26.
//  Copyright © 2023 范智渊. All rights reserved.
//

#import "JMCommonView.h"
#import "LayoutView.h"

#import "JMPickerSelectionView.h"
#import "JMPickerSelectionModel.h"
#import "PaddingView.h"
#import "LayoutScrollView.h"
#import "CustomStackView.h"

@interface JMCommonView ()
@property(nonatomic, strong) CAGradientLayer *gl;
@end
@implementation JMCommonView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
        
//        [self configureLayer];
//        [self.layer insertSublayer:self.gl atIndex:0];
        self.backgroundColor = Hex_Str_COLOR(@"#ffffff");
    }
    return self;
}

- (void)setupViews {
    
    CustomStackView *rootStack = [CustomStackView init:(UILayoutConstraintAxisHorizontal)];
    
    rootStack.translatesAutoresizingMaskIntoConstraints = NO;
    rootStack.distribution = UIStackViewDistributionFillEqually;
    rootStack.spacing = -15;
    [self addSubview:rootStack];
    [NSLayoutConstraint activateConstraints:@[
        [rootStack.topAnchor constraintEqualToAnchor:self.topAnchor constant:0],
        [rootStack.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:0],
        [rootStack.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:0],
        [rootStack.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:0],
    ]];
    
    for (int i = 0; i < 3; i ++) {
        
        CustomStackView *stack = [CustomStackView init:(UILayoutConstraintAxisVertical)];
        stack.spacing = 10;
        stack.alignment = UIStackViewAlignmentCenter;
        
        UIImageView *imageView = [UIImageView new];
        imageView.translatesAutoresizingMaskIntoConstraints = NO;
        [NSLayoutConstraint activateConstraints:@[
            [imageView.widthAnchor constraintEqualToConstant:44],
            [imageView.heightAnchor constraintEqualToConstant:44]
        ]];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [stack addArrangedSubview:imageView];
        
        UILabel *titleLab = [UILabel new];
        titleLab.textColor = [UIColor colorWithHexString:@"#1F1F1F"];
        titleLab.font = [UIFont systemFontOfSize:13 weight:(UIFontWeightSemibold)];
        [stack addArrangedSubview:titleLab];
         
        
        WeakSelf
        [rootStack addArrangedSubview:[[PaddingView initWithContentView:stack edgeInsets:(UIEdgeInsetsMake(24, 0, 16, 0))] then:^(PaddingView * _Nonnull view) {
            
            [view tapAction:^(UIView *sender) {
                        
                if (weakSelf.clickAction) {
                    weakSelf.clickAction(i);
                }
            }];
        }]];
        
        if (i == 0) {
            imageView.image = [UIImage imageNamed:@"Group 8783"];
            titleLab.text = @"FAQ";
            self.faq = stack.superview;
        }else if (i == 1) {
            imageView.image = [UIImage imageNamed:@"Group 8785"];
            titleLab.text = @"Servicio al cliente";
        }else if (i == 2) {
            imageView.image = [UIImage imageNamed:@"Group 8784"];
            titleLab.text = @"Queja";
        }
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.gl.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
}

- (void)configureLayer {
    CAGradientLayer *gl = [CAGradientLayer layer];
    self.gl = gl;
    gl.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    gl.startPoint = CGPointMake(0.5, -0.09);
    gl.endPoint = CGPointMake(0.5, 0.35);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    self.layer.cornerRadius = 12;
    self.layer.shadowColor = [UIColor colorWithRed:228/255.0 green:228/255.0 blue:228/255.0 alpha:0.1900].CGColor;
    self.layer.shadowOffset = CGSizeMake(0,7);
    self.layer.shadowOpacity = 1;
    self.layer.shadowRadius = 20;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
